﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Web;

namespace zielonka.co.uk.extensions.system.web.ui.webcontrols
{
	//Description:	Make easily accessible some functions available in HttpUtility into an Extension.
    /*
        DropDownList1.SelectItem("ABCD", Utilities.DropDownListSelectionType.ByText);
        or select by value

        DropDownList1.SelectItem("11", Utilities.DropDownListSelectionType.ByValue);
        The above code doesnt select anything if it cant find the text/value passed in.   {1,-10} {2}", i, coll.GetKey(i), coll.Get(i));

     */

    public enum DropDownListSelectionType
    {
        ByValue,
        ByText
    }

    public static partial class DropDownListExtensions
	{
        public static void SelectItem(this  System.Web.UI.WebControls.DropDownList drp, string selectedValue, DropDownListSelectionType type)
        {
            drp.ClearSelection();
            System.Web.UI.WebControls.ListItem li;
            if (type == DropDownListSelectionType.ByValue)
                li = drp.Items.FindByValue(selectedValue.Trim());
            else
                li = drp.Items.FindByText(selectedValue.Trim());
            if (li != null)
                li.Selected = true;
        }
	}
}
